package org.jeecg.glr.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.glr.entity.GlrLedTask;
import org.jeecg.glr.mapper.GlrLedTaskBindingMapper;
import org.jeecg.glr.mapper.GlrLedTaskMapper;
import org.jeecg.glr.service.IGlrLedTaskService;
import org.jeecg.glr.service.ILedCommon;
import org.jeecg.glr.util.GLRConstant;
import org.jeecg.glr.util.StringUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: LED屏定时任务
 * @Author: jeecg-boot
 * @Date:   2020-04-27
 * @Version: V1.0
 */
@Service
public class GlrLedTaskServiceImpl extends ServiceImpl<GlrLedTaskMapper, GlrLedTask> implements IGlrLedTaskService {

    @Resource
    GlrLedTaskBindingMapper glrLedTaskBindingMapper;

    @Resource
    ILedCommon ledCommon;

    @Override
    public Boolean stratTask(String ids) {
        try {
            if(StringUtil.isNotEmpty(ids)){
               List<String> idsList= Arrays.asList(ids.split(","));
                for (String id :
                        idsList) {
                    GlrLedTask ledTask = super.getById(id);
                    List<String>  codeList=  glrLedTaskBindingMapper.getLedByTaskId(id);
                    for (String code :
                            codeList) {
                        ledCommon.setTaskTime(code,ledTask.getBegtime(),ledTask.getEndtime());
                    }
                    ledTask.setStatus(GLRConstant.YN_Y);
                    super.updateById(ledTask);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }
}
